package com.face.server.dao;

import com.face.server.vo.DataClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.stereotype.Repository;

import java.util.List;

import static org.springframework.data.mongodb.core.query.Criteria.where;


@Repository
public class IndexDAO {

    @Autowired
    MongoTemplate mongoTemplate;

    public List<DataClass> count(int buildSkip, int buildLimit, boolean registered) {
        return mongoTemplate.aggregate(
                Aggregation.newAggregation(
                        Aggregation.match(where("dormitoryBuildNum").lte(buildLimit).gte(buildSkip)
                               .and("faceModels.0").exists(registered)),
                        Aggregation.group("type").count().as("count")
                ), "joined", DataClass.class
        ).getMappedResults();
    }
}


